﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;
using System.Collections.Generic;

using SBPweb.Modules.Modularity;

//using SBPweb.MediaCenter.Presentation.WF.Controls;

namespace SBPweb.MediaCenter.Modules.Player.WF
{

    public class Module : Player.Module
    {
        
        private PlayerControl pWFPlayerControl;
        //private static CultureInfo[] SUPPORTED_CULTURES = new CultureInfo[] { new CultureInfo("hu-HU"), new CultureInfo("en-US") };
        
        #region Constructor logic

        public Module(IModuleHost parent)
            : base(parent)
        {
            Name = "Player";
        }

        #endregion

        public override void Initialize()
        {
            base.Initialize();

            if (HostType != ModuleHostType.WindowsForms)
            {
                //TODO: log something
                return;
            }

        }

        public override void InitializeMenus()
        {
            /*
            MenuItemControl tsi = new MenuItemControl();
            tsi.Name = "tsiExit";
            tsi.Text = "Exit";
            tsi.Size = new System.Drawing.Size(25, 20);
            tsi.Click += new EventHandler(tsi_Click);
            pHost.Menu.Add(tsi);

            tsi = new MenuItemControl();
            tsi.Name = "tsiOpenMúvi";
            tsi.Text = "Ópen Múví";
            tsi.Size = new System.Drawing.Size(25, 20);
            tsi.Click += new EventHandler(tsi_Open);
            pHost.Menu.Add(tsi);
            */
        }

        public override void InitializeSmartparts()
        {
            pWFPlayerControl = new PlayerControl(this);
            pHost.Smartparts.Add(pWFPlayerControl);
        }

        //protected override void Play(Uri uri)
        //{
        //    pWFPlayerControl.ManagedPlayer.URL = uri.OriginalString;
        //    try
        //    {
        //        pWFPlayerControl.ManagedPlayer.dvd.topMenu();
        //    }
        //    catch
        //    {
        //    }
        //}

        void tsi_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        void tsi_Open(object sender, EventArgs e)
        {
            OpenFileDialog ofdBrowse = new System.Windows.Forms.OpenFileDialog();
            DialogResult dR = ofdBrowse.ShowDialog();
            if (dR == DialogResult.OK)
            {
                pWFPlayerControl.ManagedPlayer.URL = ofdBrowse.FileName;

                string text = string.Format("Loaded: {0}", ofdBrowse.FileName);

                //Communication.Message message = new Communication.Message(this, text);
                //this.Host.Messages.Enqueue(message);
            }
        }

        public override void LoadPersistency()
        {
            throw new NotImplementedException();
        }

        public override void SavePersistency()
        {
            throw new NotImplementedException();
        }

        public override void Terminate()
        {
            //throw new NotImplementedException();
        }
    }
}
